package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.entity.ArchiveCancel;
import com.amsp.oa.oademo.service.IArchiveCancelService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "档案注销管理")
@RestController
@RequestMapping("/api/archive-cancel")
public class ArchiveCancelController {

    @Autowired
    private IArchiveCancelService archiveCancelService;

    @ApiOperation("分页查询档案注销记录")
    @GetMapping("/page")
    public Result<IPage<ArchiveCancel>> getPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer page,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("员工姓名") @RequestParam(required = false) String employeeName,
            @ApiParam("员工工号") @RequestParam(required = false) String employeeNumber) {

        IPage<ArchiveCancel> pageResult = archiveCancelService.getPage(page, size, employeeName, employeeNumber);
        return Result.ok(pageResult);
    }

    @ApiOperation("获取档案注销详情")
    @GetMapping("/{id}")
    public Result<ArchiveCancel> getById(@ApiParam("ID") @PathVariable Long id) {
        return Result.ok(archiveCancelService.getById(id));
    }

    @ApiOperation("批量保存或更新档案注销记录")
    @PostMapping("/batch")
    public Result<Boolean> saveOrUpdateBatch(@RequestBody @Validated List<ArchiveCancel> records) {
        return Result.ok(archiveCancelService.saveOrUpdateBatchTransactional(records));
    }

    @ApiOperation("删除档案注销记录")
    @DeleteMapping("/{id}")
    public Result<Boolean> removeById(@ApiParam("ID") @PathVariable Long id) {
        return Result.ok(archiveCancelService.removeById(id));
    }

    @ApiOperation("批量删除档案注销记录")
    @DeleteMapping("/batch")
    public Result<Boolean> removeBatchByIds(@ApiParam("ID列表") @RequestBody Long[] ids) {
        return Result.ok(archiveCancelService.removeByIds(java.util.Arrays.asList(ids)));
    }
}